Structured and logical programming or coding techniques serve many purposes in the life cycle of a given software design. Such designs are generally implemented with a plurality of different programming languages where the cycle begins within the framework of some type of source code development program or environment. Well-written programs that are designed properly help to serve the various needs of the software life cycle. These needs or goals generally include code design, debug, testing, deployment, and maintenance. The design phase is often the most crucial since it will generally have an impact on all the phases that follow. Thus, to support these goals, code should be logically written and in a format that is easily readable in order to facilitate future debug, testing and so forth. This type of coding generally includes a structure where instructions are indented in the source code to indicate transitions from one type of instruction to another such as to indicate that an inner loop is about to occur within the boundaries of some other instruction such as an outer loop. Another feature of well-written programs is via the liberal employment of comments to indicate the design purpose of any given sequence of code.
Along with actual instructions in a source code program, other type of strings or literals may appear. One example of these types of literals are referred to as a here-documents (or here-doc). A here-document refers to a way of embedding one document, formatted in one way into another enclosing document, often formatted in a different way, where the two document formats would clash. The term may have originated with BourneShell, which uses two left-angle-brackets followed by a sequence of characters, followed by the content, followed by a line containing nothing but the sequence of characters, i.e., as in the following example:
Usage( )echo <<FOOBARHELPThis program rearranges the foobars installed on computersystem. To use, invoke with the following options: <opt 1 opt 2>FOOBARHELP
Many other programming languages—most notably scripting languages and markup formats, employ here documents. For instance, PerlLanguage uses a syntax similar to BourneShell. PythonLanguage uses three double quotes to begin and end here documents, whereas ExtensibleMarkupLanguage (XML) uses CDATA sections. Here-documents also provide a popular way of creating multi-line strings. The beginning of the string introduces a marker, in the following example EOS. All the text from the next line after the start tag to the occurrence of the marker is taken as a verbatim string:
example = <<EOSVerbatim stringUsing classichere-doc syntaxEOS
In one example, the C# language offers a simple form of heredoc string using @” as the fixed start tag and “as the fixed end tag. Verbatim strings require embedded quotes to be escaped as “” (two quotes). One of the main problems with here-doc literals is that everything from just after the start marker to just before the end marker is part of the resulting string. This is inconvenient if one needed to create a string nested inside a program since the here-doc breaks the indentation flow of the program as in the following example (the string content is bold):
Class CFunction M( ) As StringDim S As StringIf True ThenS = <<EOSAlongstringEOSElseS = <<EOSAnotherlong stringEOSEnd IfEnd FunctionEnd Class
A similar problem occurs with other literals where white space is relevant, for example XML literals. Again, the following example shows how the normal indentation flow of the program is disrupted:
Class CFunction M( ) As StringDim S As StringIf True ThenS = <Person><Name>John Doe</Name></Person>ElseS = —<Person><Name>Jane Doe</Name></Person>End IfEnd FunctionEnd Class